<template>
  <el-dialog :title="title" :visible.sync="dialogVisible" top="8vh" width="35%" :before-close="cancel">
    <el-form :model="formValue" ref="ruleForm" label-width="85px">
      <el-form-item label="文件名：" v-if="!formValue.isFolder">
        <svg class="icon" aria-hidden="true">
          <use :xlink:href="formValue.fileType"></use>
        </svg>
        <span>{{formValue.fileName}}</span>
      </el-form-item>
      <el-form-item label="文件夹名：" v-if="formValue.isFolder">
        <svg class="icon" aria-hidden="true">
          <use xlink:href="#icon-wenjianjia"></use>
        </svg>
        <span>{{formValue.folderName}}</span>
      </el-form-item>
      <el-form-item label="位置：">
        <span>{{folderPath | folderPathFilter}}</span>
      </el-form-item>
      <el-form-item label="大小：">
        <span>{{formValue.size | fileSizeFilter}}KB&nbsp; （{{formValue.size}}）字节</span>
      </el-form-item>
      <el-form-item label="包含：" v-if="formValue.isFolder">
        <span>{{formValue.fileSize}}个文件，{{formValue.folderSize}}个文件夹</span>
      </el-form-item>
      <el-form-item label="创建时间：">
        <span>{{formValue.createTime}}</span>
      </el-form-item>
      <el-form-item label="修改时间：" v-if="!formValue.isFolder">
        <span>{{formValue.updateTime}}</span>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
      <el-button type="primary" @click="sure">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {mapState} from 'vuex'
  export default {
    name: 'AttrDialog',
    computed: mapState({
      dialogVisible: state => state.dialog.attrDialogVisible,
      folderPath: state => state.folder.currentPath.paths
    }),
    props: {
      formValue: {
        type: Object,
        default () {
          return {}
        }
      },
      title: {
        type: String,
        default () {
          return '文件属性'
        }
      }
    },
    methods: {
      cancel () {
        this.$store.commit('setAttrDialogVisible')
      },
      sure () {
        console.log(this.folderPath)
        this.$store.commit('setAttrDialogVisible')
      }
    },
    filters: {
      fileSizeFilter (value) {
        let realVal = Number(value / 1024).toFixed(2)
        return Number(realVal)
      },
      folderPathFilter(value) {
        let path = '/'
        value.forEach(v => {
          path += v + '/'
        })
        return path.substring(0, path.length - 1)
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
